package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
@ToString
/**
 * 礼品主题明细实体类
 */
public class ThemeDetail extends BaseDomain{

    //明细标题
    private String title;

    //明细副标题
    private String subTitle;

    //明细封面
    private String coverUrl;

    //发布时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GMT+8")
    private Date releaseTime;

    //明细价格
    private BigDecimal price;

    //所属主题
    private ThemeCatalog catalog;

    //明细状态
    private Integer state = STATE_COMMON;

    public static final int STATE_COMMON = 0;//草稿
    public static final int STATE_RELEASE = 1;//发布
    public static final int STATE_DISABLE= -1;//禁用

    //明细内容
    private ThemeContent themeContent;

    //封装后台主题明细网页需要的数据
    public String getStateName(){
        String stateName = "";
        switch (state){
            case 0:stateName = "草稿"; break;
            case 1:stateName = "发布"; break;
            case -1:stateName = "禁用"; break;
        }
        return stateName;
    }

    //封装后台主题明细网页需要的数据
    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("subTitle",subTitle);
        map.put("coverUrl",coverUrl);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        map.put("releaseTime",simpleDateFormat.format(releaseTime));
        map.put("price",price);
        if(catalog!=null){
            map.put("catalogId",catalog.getId());
            map.put("catalogName",catalog.getTitle());
        }
        map.put("state",state);
        return JSON.toJSONString(map);
    }
}